package com.gupaoedu.baifc.simplefactory;

import com.gupaoedu.baifc.ICourse;

/**
 * projectName: baifc_factory
 * packageName: com.gupaoedu.baifc.simplefactory
 * Created: 2019/3/11.
 * Auther: baifc
 */
public class ICourseFactory {

//    public ICourse create(String name) {
//        ICourse iCourse = null;
//        if ("java".equals(name)) {
//            iCourse = new JavaCourse();
//        } else if ("python".equals(name)) {
//            iCourse = new PythonCourse();
//        }
//
//        return iCourse;
//    }

    // 使用反射
    public ICourse create(String className) {
        ICourse iCourse = null;
        if (className != null && !"".equals(className)) {
            try {
                iCourse = (ICourse) Class.forName(className).newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return iCourse;
    }

    // 直接传class
    public ICourse create(Class clazz) {
        ICourse iCourse = null;
        if (clazz != null) {
            try {
                iCourse = (ICourse) clazz.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return iCourse;
    }
}
